<?php
namespace app\models;

use pqphp\base\Model;
use pqphp\db\Db;

/**
 * 用户Model
 */
class WebPayModel extends Model
{
    /**
     * 自定义当前模型操作的数据库表名称，
     * 如果不指定，默认为类名称的小写字符串，
     * 这里就是 item 表
     * @var string
     */
    protected $table = 'auther';

    /**
     * 搜索功能，因为Sql父类里面没有现成的like搜索，
     * 所以需要自己写SQL语句，对数据库的操作应该都放
     * 在Model里面，然后提供给Controller直接调用
     * @param $title string 查询的关键词
     * @return array 返回的数据
     */
    public function finduser($keyword)
    {
		//产生一条查询日志
        $sql = "select * from auther where `id` like :keyword";
        $sth = Db::pdo()->prepare($sql);
        $sth = $this->formatParam($sth, [':keyword' => "%$keyword%"]);
        $sth->execute();
        return $sth->fetchAll();
    }

	public function finduserbypid($keyword)
    {
		//产生一条查询日志
        $sql = "select * from auther where `pid` like :keyword";
        $sth = Db::pdo()->prepare($sql);
        $sth = $this->formatParam($sth, [':keyword' => "%$keyword%"]);
        $sth->execute();
        return $sth->fetchAll();
    }


	/**
     * @根据用户的pid查询需要银联支付的参数
     * @return array 返回的数据
     */
	public function findunionmodel($keyword)
	{
		$sql = "select msgSrcId,msgSrc,mid,tid,instMid,msgType,notifyUrl,isuse,msgType,id,`key` from unionpay where `pid` like :keyword";
        $sth = Db::pdo()->prepare($sql);
        $sth = $this->formatParam($sth, [':keyword' => "%$keyword%"]);
        $sth->execute();
        return $sth->fetchAll();
	}

	public function findwechatmodel($keyword,$submch=false)
	{
		if($submch)
		{
			$sql = "select appid,mch_id,body,notify_url,`key`,wap_url,wap_name,id,isuse,appsecret,sub_appid,sub_mch_id from wechatpay where `pid` like :keyword";
		}
		else
		{
			$sql = "select appid,mch_id,body,notify_url,`key`,wap_url,wap_name,id,isuse,appsecret from wechatpay where `pid` like :keyword";
		}
        $sth = Db::pdo()->prepare($sql);
        $sth = $this->formatParam($sth, [':keyword' => "%$keyword%"]);
        $sth->execute();
        return $sth->fetchAll();
	}
}